﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Windows;
using RiskMan.DataClass.Models.NotBasModels;

namespace RiskMan.DataClass.Models.Plaza_II
{
    /// <summary>
    /// Значение робота по PlazaII
    /// </summary>
    [Serializable]
    public class RobotItemPlazaII : INotifyPropertyChanged, ISerializable
    {
         #region private

        //Базовые настройки
        private bool _isRun;
        private bool _check;
        private string _account;
        private string _clientCode;
        private string _instrument;
        private int _instrumentId;
        private Guid _guidItem;
        

        //рабочие настройки робота

        private int _numTicksForSmallCross;
        private int _numTicksForBigCross;
        private int _quantity;

        //Индикаторы
        private int _smallSlowForSignalLine;
        private int _smallFastForSignalLine;
        private int _smallMacd;

        private int _bigSlowForSignalLine;
        private int _bigFastForSignalLine;
        private int _bigMacd;

        private int _numTicksForInit;

        private int _smallPivotHigh;
        private int _smallPivotLow;

        private int _bigPivotHigh;
        private int _bigPivotLow;

        private double _priceOpenPoz;
        private int _curPosition;
        private double _lastPrice;
        private ObservableCollection<TradesOpen> _TradeList;


        private SettingOrderOpenClosePoz _SettingOrderOpenClose;

        private int _numTicksForCrossSmall;
        private int _numTicksForCrossBig;
        #endregion

        #region public

        #region Базовые настройки

        /// <summary>
        /// Торговый счет
        /// </summary>
        public string Account
        {
            get { return _account; }
            set
            {
                if (_account != value)
                {
                    _account = value;
                    RaisePropertyChanged("Account");
                }
            }
        }

        /// <summary>
        /// Счет депо
        /// </summary>
        public string ClientCode
        {
            get { return _clientCode; }
            set
            {
                if (_clientCode != value)
                {
                    _clientCode = value;
                    RaisePropertyChanged("ClientCode");
                }
            }
        }

        /// <summary>
        /// Торгуемый инструмент
        /// </summary>
        public string Instrument
        {
            get { return _instrument; }
            set
            {
                if (_instrument != value)
                {
                    _instrument = value;
                    RaisePropertyChanged("Instrument");
                }
            }
        }

        /// <summary>
        /// Запуск/остановка работы по данному инструменту
        /// </summary>
        public bool IsRun
        {
            get { return _isRun; }
            set
            {
                if (_isRun != value)
                {
                    _isRun = value;
                    RaisePropertyChanged("IsRun");
                }
            }
        }

        public bool Check
        {
            get { return _check; }
            set
            {
                if (_check != value)
                {
                    _check = value;
                    RaisePropertyChanged("Check");
                }
            }
        }

        /// <summary>
        /// уникальный номер робота Жилевского, чтоб не терялся при сортировке
        /// </summary>
        public Guid GuidItem
        {
            get { return _guidItem; }
            set
            {
                if (_guidItem != value)
                {
                    _guidItem = value;
                    RaisePropertyChanged("GuidItem");
                }
            }
        }
        #endregion

        #region Настройки робота
        /// <summary>
        /// Количество контрактов/лотов, в одной выставляемой заявке
        /// </summary>
        public int Quantity
        {
            get { return _quantity; }
            set
            {
                if (_quantity != value)
                {
                    _quantity = value;
                    RaisePropertyChanged("Quantity");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int NumTicksForSmallCross
        {
            get { return _numTicksForSmallCross; }
            set
            {
                if (_numTicksForSmallCross != value)
                {
                    _numTicksForSmallCross = value;
                    RaisePropertyChanged("NumTicksForSmallCross");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int NumTicksForBigCross
        {
            get { return _numTicksForBigCross; }
            set
            {
                if (_numTicksForBigCross != value)
                {
                    _numTicksForBigCross = value;
                    RaisePropertyChanged("NumTicksForBigCross");
                }
            }
        }
           
        #endregion

        #region Индикаторы

        
        /// <summary>
        /// Уникальный номер инструмента
        /// </summary>
        public int InstrumentId
        {
            get { return _instrumentId; }
            set
            {
                if (_instrumentId != value)
                {
                    _instrumentId = value;
                    RaisePropertyChanged("InstrumentId");
                }
            }
        }
           
        
        /// <summary>
        /// 
        /// </summary>
        public int SmallSlowForSignalLine
        {
            get { return _smallSlowForSignalLine; }
            set
            {
                if (_smallSlowForSignalLine != value)
                {
                    _smallSlowForSignalLine = value;
                    RaisePropertyChanged("SmallSlowForSignalLine");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int SmallFastForSignalLine
        {
            get { return _smallFastForSignalLine; }
            set
            {
                if (_smallFastForSignalLine != value)
                {
                    _smallFastForSignalLine = value;
                    RaisePropertyChanged("SmallFastForSignalLine");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int SmallMacd
        {
            get { return _smallMacd; }
            set
            {
                if (_smallMacd != value)
                {
                    _smallMacd = value;
                    RaisePropertyChanged("SmallMacd");
                }
            }
        }

        
        /// <summary>
        /// 
        /// </summary>
        public int BigSlowForSignalLine
        {
            get { return _bigSlowForSignalLine; }
            set
            {
                if (_bigSlowForSignalLine != value)
                {
                    _bigSlowForSignalLine = value;
                    RaisePropertyChanged("BigSlowForSignalLine");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int BigFastForSignalLine
        {
            get { return _bigFastForSignalLine; }
            set
            {
                if (_bigFastForSignalLine != value)
                {
                    _bigFastForSignalLine = value;
                    RaisePropertyChanged("BigFastForSignalLine");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int BigMacd
        {
            get { return _bigMacd; }
            set
            {
                if (_bigMacd != value)
                {
                    _bigMacd = value;
                    RaisePropertyChanged("BigMacd");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int NumTicksForInit
        {
            get { return _numTicksForInit; }
            set
            {
                if (_numTicksForInit != value)
                {
                    _numTicksForInit = value;
                    RaisePropertyChanged("NumTicksForInit");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int SmallPivotHigh
        {
            get { return _smallPivotHigh; }
            set
            {
                if (_smallPivotHigh != value)
                {
                    _smallPivotHigh = value;
                    RaisePropertyChanged("SmallPivotHigh");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int SmallPivotLow
        {
            get { return _smallPivotLow; }
            set
            {
                if (_smallPivotLow != value)
                {
                    _smallPivotLow = value;
                    RaisePropertyChanged("SmallPivotLow");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int BigPivotHigh
        {
            get { return _bigPivotHigh; }
            set
            {
                if (_bigPivotHigh != value)
                {
                    _bigPivotHigh = value;
                    RaisePropertyChanged("BigPivotHigh");
                }
            }
        }
        
        /// <summary>
        /// 
        /// </summary>
        public int BigPivotLow
        {
            get { return _bigPivotLow; }
            set
            {
                if (_bigPivotLow != value)
                {
                    _bigPivotLow = value;
                    RaisePropertyChanged("BigPivotLow");
                }
            }
        }
                     
        #endregion

        /// <summary>
        /// Настройки типов заявок и стоп-заявок на открытие и закрытие позиций
        /// </summary>
        public SettingOrderOpenClosePoz SettingOrderOpenClose
        {
            get { return _SettingOrderOpenClose; }
            set
            {
                if (_SettingOrderOpenClose != value)
                {
                    _SettingOrderOpenClose = value;
                    RaisePropertyChanged("SettingOrderOpenClose");
                }
            }
        }

        /// <summary>
        /// текущая позиция по уровню и инструменту
        /// </summary>
        public int CurPosition
        {
            get { return _curPosition; }
            set
            {
                if (_curPosition != value)
                {
                    _curPosition = value;
                    RaisePropertyChanged("CurPosition");
                }
            }
        }

        /// <summary>
        /// Цена открытия позиции
        /// </summary>
        public double PriceOpenPoz
        {
            get { return _priceOpenPoz; }
            set
            {
                if (_priceOpenPoz != value)
                {
                    _priceOpenPoz = value;
                    RaisePropertyChanged("PriceOpenPoz");
                }
            }
        }

        /// <summary>
        /// Цена последней сделки
        /// </summary>
        public double LastPrice
        {
            get { return _lastPrice; }
            set
            {
                if (_lastPrice != value)
                {
                    _lastPrice = value;
                    RaisePropertyChanged("LastPrice");
                }
            }
        }

        /// <summary>
        /// коллекция активнных и исполненных сделок на открытие и закрытие позиции
        /// </summary>
        public ObservableCollection<TradesOpen> TradeList
        {
            get { return _TradeList; }
            set
            {
                if (_TradeList != value)
                {
                    _TradeList = value;
                    RaisePropertyChanged("TradeList");
                }
            }
        }

        
        /// <summary>
        /// Количество тиков для подачи сигнала на малом макди
        /// </summary>
        public int NumTicksForCrossSmall
        {
            get { return _numTicksForCrossSmall; }
            set
            {
                if (_numTicksForCrossSmall != value)
                {
                    _numTicksForCrossSmall = value;
                    RaisePropertyChanged("NumTicksForCrossSmall");
                }
            }
        }
        
        /// <summary>
        /// Количество тиков для подачи сигнала на большом макди
        /// </summary>
        public int NumTicksForCrossBig
        {
            get { return _numTicksForCrossBig; }
            set
            {
                if (_numTicksForCrossBig != value)
                {
                    _numTicksForCrossBig = value;
                    RaisePropertyChanged("NumTicksForCrossBig");
                }
            }
        }

        #endregion

        public RobotItemPlazaII() { }

        #region event PropertyChangedEventHandler

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        public RobotItemPlazaII(SerializationInfo info, StreamingContext context)
        {
            IsRun = info.GetBoolean("IsRun");
            Account = info.GetString("Account");
            ClientCode = info.GetString("ClientCode");
            Instrument = info.GetString("Instrument");
            GuidItem = (Guid)info.GetValue("GuidItem", typeof(Guid));

            Quantity = info.GetInt32("Quantity");
            
            SettingOrderOpenClose = (SettingOrderOpenClosePoz)info.GetValue("SettingOrderOpenClose", typeof(SettingOrderOpenClosePoz));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("IsRun", IsRun);
            info.AddValue("Account", Account);
            info.AddValue("ClientCode", ClientCode);
            info.AddValue("Instrument", Instrument);
            info.AddValue("GuidItem", GuidItem);

            info.AddValue("Quantity", Quantity);
            info.AddValue("SettingOrderOpenClose", SettingOrderOpenClose);

            }
    }
}
